package mrms.api.web.utils;

import com.fasterxml.jackson.annotation.JsonView;
import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author lenchu
 * @date 2019/01/31
 */
@Data
@Accessors(chain = true)
public class Result {
    private int code;
    private String msg;
    private Object data;
    private Object errors;

    public static Result success(String msg, Object data) {
        return new Result().setCode(0).setMsg(msg).setData(data);
    }

    public static Result success(Object data) {
        return success("请求成功", data);
    }

    public static Result error(String msg) {
        return new Result().setCode(1).setMsg(msg);
    }

    public static Result error(String msg, Object errors) {
        return error(msg).setErrors(errors);
    }

    public static Result error(Object errors) {
        return error("请求失败", errors);
    }
}
